home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / spacewar / logon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-31  |  2.5 KB  |  131 lines

  1. /*
  2.  * Spacewar - logon a player
  3.  *          clear out most of the login structure
  4.  *          set tty modes
  5.  *          prompt player for his/her name
  6.  *
  7.  * Copyright 1984 obo Systems, Inc.
  8.  * Copyright 1984 Dan Rosenblatt
  9.  */
  10.  
  11. #include "spacewar.h"
  12. #include "universe.h"
  13. #include "login.h"
  14.  
  15. #ifdef BSD
  16. #    include <sgtty.h>
  17. #else /* VMS SYSIII SYSV */
  18. #ifndef VMS
  19. #    include <sys/types.h>
  20. #    include <sys/ioctl.h>
  21. #    include <termio.h>
  22. #endif /* VMS SYSIII SYSV */
  23. #endif /* BSD VMS SYSIII SYSV */
  24.  
  25. VOID logon(plogin)
  26. register struct login *plogin;
  27. {
  28.  
  29. #ifdef DEBUG
  30.     DBG("logon(#%d/%s)\n",plogin-loginlst,plogin->ln_name);
  31. #endif
  32.  
  33.     /* clear out most of login structure */
  34.     plogin->ln_name[0] = NULL;
  35.     if (plogin->ln_term)
  36.         free(plogin->ln_term);
  37.     plogin->ln_term = NULL;
  38.     if (plogin->ln_tcm)
  39.         free(plogin->ln_tcm);
  40.     plogin->ln_tcm = NULL;
  41.     if (plogin->ln_tcl)
  42.         free(plogin->ln_tcl);
  43.     plogin->ln_tcl = NULL;
  44.     if (plogin->ln_tce)
  45.         free(plogin->ln_tce);
  46.     plogin->ln_tce = NULL;
  47.     if (plogin->ln_tso)
  48.         free(plogin->ln_tso);
  49.     plogin->ln_tso = NULL;
  50.     if (plogin->ln_tse)
  51.         free(plogin->ln_tse);
  52.     plogin->ln_tse = NULL;
  53.     plogin->ln_rvslh = 0;
  54.     plogin->ln_iomode = NULL;
  55.     plogin->ln_crft[0] = NULL;
  56.     plogin->ln_play.ip_ptr = NULL;
  57.     plogin->ln_stat = NULL;
  58.     plogin->ln_substat = NULL;
  59.     plogin->ln_input[0] = NULL;
  60.  
  61.     /*****************/
  62.     /* set tty modes */
  63.     /*****************/
  64. #ifdef BSD
  65.     {
  66.     struct sgttyb tmode;
  67.  
  68.     if (gtty(plogin->ln_tty,&tmode)) {
  69.         perror("gtty");
  70.         logoff(plogin);
  71. #ifdef DEBUG
  72.         VDBG("logon return\n");
  73. #endif
  74.         return;
  75.     }
  76.  
  77.     /* insure no echo and cbreak mode */
  78.     /* (too bad the previous states aren't saved)  */
  79.     tmode.sg_flags |= CBREAK;
  80.     tmode.sg_flags &= ~(RAW+ECHO);
  81.  
  82.     if (stty(plogin->ln_tty,&tmode)) {
  83.         perror("stty");
  84.         logoff(plogin);
  85. #ifdef DEBUG
  86.         VDBG("logon return\n");
  87. #endif
  88.         return;
  89.     }
  90.     }
  91. #else /* VMS SYSIII SYSV */
  92. #ifndef VMS
  93.     {
  94.     struct termio tmode;
  95.  
  96.     if (ioctl(plogin->ln_tty,TCGETA,&tmode)) {
  97.         perror("ioctl TCGETA");
  98.         logoff(plogin);
  99. #ifdef DEBUG
  100.         VDBG("logon return\n");
  101. #endif
  102.         return;
  103.     }
  104.  
  105.     /* insure no echo and no erase/kill edit processing */
  106.     /* (too bad the previous states aren't saved)  */
  107.     tmode.c_lflag &= ~(ICANON+ECHO+ECHOE+ECHOK+ECHONL);
  108.     tmode.c_cc[VMIN] = 1;
  109.     tmode.c_cc[VTIME] = 0;
  110.  
  111.     if (ioctl(plogin->ln_tty,TCSETA,&tmode)) {
  112.         perror("ioctl TCSETA");
  113.         logoff(plogin);
  114. #ifdef DEBUG
  115.         VDBG("logon return\n");
  116. #endif
  117.         return;
  118.     }
  119.     }
  120. #endif /* VMS */
  121. #endif /* VMS BSD SYSIII SYSV */
  122.  
  123.  
  124.     /* prompt player for name */
  125.     output(plogin,'C',0,"\nWhat is your name?");
  126.     output(plogin,0,0,0);
  127. #ifdef DEBUG
  128.     VDBG("logon return\n");
  129. #endif
  130. }
  131.